package java;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        // 幸运数字
//        int[][] matrix = {{3,7,8},{9,11,13},{15,16,17}};
//        System.out.println(LuckyNumbers(matrix));

        //求和
        int[] nums = {2,7,11,12};
        int target = 9;
        System.out.println(Arrays.toString(twoSum(nums,target)));
    }

    // 求和
    private static int[] twoSum(int[] nums, int target) {
        int[] ret = new int[2];
        for(int i = 0; i < nums.length - 1 ; i ++){
            for(int j = i + 1 ; j < nums.length ; j ++){
                if(nums[i] + nums[j] == target){
                    ret[0] = i;
                    ret[1] = j;
                    return ret;
                }
            }
        }
        return ret;
    }

    // LuckyNumbers
    private static List<Integer> LuckyNumbers(int[][] matrix) {
        List<Integer> result = new LinkedList<>();
        int t = 0;
        for (int[] row: matrix){
            int min = Integer.MAX_VALUE;
            int index = -1;
            for(int i = 0; i < row.length ; i ++){
                if(min > row[i]){
                    min = row[i];
                    index = i;
                }
            }

            if(isMaxInColumn(index,min,matrix)){
                result.add(min);
                t ++;
            }

        }

        return result;


    }

    private static boolean isMaxInColumn(int index, int min, int[][] matrix) {
        int max = Integer.MIN_VALUE;
        for (int i = 1; i < matrix.length;i++){
            if (matrix[i][index] > max){
                max = matrix[i][index];
            }
        }

        if (min == max){
            return true;
        }
        return false;
    }


}
